﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Utils.Extentions
{
    public static class StringExtentions
    {
        public static int ToIntIntegralPart(this System.String stringInt)
        {
            if (stringInt.Contains("."))
            {
                var dotPosition = stringInt.IndexOf('.');
                stringInt = stringInt.Substring(0, dotPosition);
            }
            else if (stringInt.Contains(","))
            {
                var commaPosition = stringInt.IndexOf('.');
                stringInt = stringInt.Substring(0, commaPosition);
            }

            int result = 0;

            try
            {
                result = Convert.ToInt32(stringInt);
            }
            catch
            {
                throw new ArgumentException("Wrong input string format");
            }

            return result;
        } 
    }
}
